<template>
  <div class="audition169">
    <p>监听<span class="color">visibilitychange</span>事件</p>
    <code class="code">
      document.<span class="color">addEventListener</span>('<span class="color2">visibilitychange</span>', <span class="color3">function</span> () {<br />
        <span class="indient">// 获取当前页面是否被隐藏</span><br />
        <span class="indient"><span class="color3">var</span> <span class="color4">isHide</span> = <span class="color1">document</span>.hidden</span><br />
        <span class="indient">// 如果当前页面隐藏了，就清除定时器</span><br />
        <span class="indient"><span class="color3">if</span>(isHide) {</span><br />
          <span class="indient2"><span class="color">clearInterval</span>(timer)</span><br />
        <span class="indient">}</span><br />
      })
    </code>
  </div>
</template>

<script>
export default {
  name: 'Audition169'
}
</script>

<style>

</style>